<script setup lang="ts">
import {ref} from "vue";
import {Editingdata, Modify} from "@/http/Personal center";
import {useCounterStore} from "@/stores/SaveUser";
import {useRouter} from "vue-router";

const nameone = useCounterStore()

const show = ref(false);
const show1 = ref(false);
const routerPass=useRouter()
//
// const name1=ref('')
//

const actions = [
    {name: '女'},
    {name: '男'},
];

//pinia
// const gradeUserInfo = ref({
//     id:482235006186557440 ,
//     nickname:"",
//     gender:"",
//     birthday:""
// })
//

const Handover = (item1) => {
    // name1.value=item1.name
    nameone.gradeUserInfo.gender = item1.name
    // console.log(nameone.gradeUserInfo.gender)
    Modify(nameone.gradeUserInfo).then(res => {
        console.log(res)
    })
}

const showPopup1 = () => {
    show1.value = true;
};
const minDate =new Date (2000,1,1)
const maxDate =new Date(2024,1,1)

const formatter = (type, option) => {
    if (type === 'year') {
        option.text += '年';
    }
    if (type === 'month') {
        option.text += '月';
    }
    if (type === 'day') {
        option.text += '日';
    }
    return option;

};
// const name = ref('')
const Close = (item) => {
    nameone.gradeUserInfo.birthday = item.selectedValues[0] + '-' + item.selectedValues[1] + '-' + item.selectedValues[2]
    console.log(nameone.gradeUserInfo.birthday)
    Modify(nameone.gradeUserInfo).then(res => {
    })
    item.birthday = item.selectedValues[0] + '-' + item.selectedValues[1] + '-' + item.selectedValues[2]
    show1.value = false;

}
let baseUrl = 'http://192.168.5.120:8090'
const cancel = () => {
    show1.value = false;
}
const pictureone=ref('')
const namee=ref({})
function eow(){
    Editingdata().then(res => {
        if (res.code === 200) {
            console.log(res.data)
            namee.value=res.data
            pictureone.value=res.data.avatar
            nameone.userInfo = res.data
            console.log(nameone.userInfo)
            nameone.gradeUserInfo.nickname = res.data.nickname
            nameone.gradeUserInfo.gender = res.data.gender
            nameone.gradeUserInfo.birthday = res.data.birthday
            nameone.gradeUserInfo.id = res.data.id
        }
    })
}
eow()
function pass(){
    routerPass.push({path:'/xiugaitouxiang',query:{src:pictureone.value}})
}

</script>

<template>
    <div id="beijing">
        <router-link to="/gerenzhongxin">
            <van-nav-bar
                    left-text="编辑资料"
                    left-arrow
            />
        </router-link>
        <!--      修改头像-->
        <van-cell  id="one" @click="pass">
            <template #title >
              <span class="custom-title">
                  头像
               <div class="right">
                  <van-image
                          width="66"
                          height="66"
                          :src="baseUrl+pictureone"
                  />
              </div>
              </span>
            </template>
        </van-cell>
        <!--      修改昵称-->
        <van-cell title="昵称" is-link to="/xiugaimingcheng">
            {{ nameone.gradeUserInfo.nickname }}
        </van-cell>
        <!--      修改性别-->
        <van-cell title="性别" is-link v-model:value="nameone.gradeUserInfo.gender" @click="show = true"/>
        <van-action-sheet
                v-model:show="show"
                :actions="actions"
                cancel-text="取消"
                close-on-click-action
                @select="Handover"
        />
<!--              修改生日-->
        <van-cell title="生日" is-link v-model:value="nameone.gradeUserInfo.birthday" @click="showPopup1"/>
        <van-popup
                v-model:show="show1"
                round
                position="bottom"
                :style="{ height: '30%' }"
        >
            <van-date-picker
                    v-model="currentDate"
                    title="选择年月"
                    :min-date="minDate"
                    :max-date="maxDate"
                    :formatter="formatter"
                    @confirm="Close"
                    @cancel="cancel"
            />
        </van-popup>

        <!--      班级-->
        <van-cell title="班级">
            {{ nameone.userInfo.college }}
        </van-cell>
        <!--      学号-->
        <van-cell title="学号">
            {{ nameone.userInfo.stuNum }}
        </van-cell>
        <!--      学历-->
        <van-cell title="学历">
            {{ nameone.userInfo.education }}
        </van-cell>
        <!--      入学时间-->
        <van-cell title="入学时间">
            {{ nameone.userInfo.enrollmentTime }}
        </van-cell>
    </div>
</template>

<style scoped lang="less">
#beijing {
    background-color: #f4f4f4;
    height: 600px;

    :deep(.van-nav-bar__content) {
        background-color: #f4f4f4;
    }

    #one {
        height: 80px;
        line-height: 80px;

        .custom-title {
            display: flex;
            justify-content: space-between;

            .right {
                :deep(.van-image__img) {
                    border-radius: 33px;
                }

                img {
                    width: 100%;
                    height: 100%;
                    border-radius: 33px;
                }
            }
        }

    }
}

</style>